package com.tenbent.product.center.insures.service.impl;

import com.tenbent.product.base.service.impl.BaseServiceImpl;
import com.tenbent.product.center.insures.bo.SafeguardCategoryType;
import com.tenbent.product.center.insures.dto.SafeguardCategoryDto;
import com.tenbent.product.center.insures.dto.SafeguardCategoryTypeDto;
import com.tenbent.product.center.insures.mapper.SafeguardCategoryTypeMapper;
import com.tenbent.product.center.insures.service.SafeguardCategoryService;
import com.tenbent.product.center.insures.service.SafeguardCategoryTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by ThinkPad on 2017/8/21.
 */
@Service(value = "safeguardCategoryTypeServiceImpl")
public class SafeguardCategoryTypeServiceImpl extends BaseServiceImpl<SafeguardCategoryType>
		implements SafeguardCategoryTypeService {

	public SafeguardCategoryTypeServiceImpl() {
		this.setClazz(SafeguardCategoryType.class);
	}

	@Autowired
	private SafeguardCategoryTypeMapper safeguardCategoryTypeMapper;

	@Autowired
	@Qualifier("safeguardCategoryServiceImpl")
	private SafeguardCategoryService safeguardCategoryService;

	@Override
	public List<SafeguardCategoryTypeDto> findSafeguardCategoryTypeByProductId(Integer productId) {

		SafeguardCategoryType query = new SafeguardCategoryType();
		query.setProductId(productId);
		List<SafeguardCategoryTypeDto> list = change.changesToDTOList(this.queryObj(query),
				SafeguardCategoryTypeDto.class);
		for (SafeguardCategoryTypeDto safeguardCategoryType : list) {
			List<SafeguardCategoryDto> safeguardCategorys = safeguardCategoryService
					.findSafeguardCategoryByCode(safeguardCategoryType.getTypeCode());
			if (safeguardCategoryType.getSafeguardCategorys() == null) {
				safeguardCategoryType.setSafeguardCategorys(safeguardCategorys);
			}
		}
		return list;
	}
}
